<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 22328
  Date: 2021/2/12
  Time: 22:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>焕耀商城－个人地址</title>
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="./lib/layui/css/layui.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
</head>
<body>

<!--头部 开始-->
<jsp:include page="top.jsp"/>
<!--头部 结束-->

<!--左边目录 开始-->
<div class="search_bar clearfix">
    <a href="./main" class="logo fl"><img src="./images/logo.png"></a>
    <div class="sub_page_name fl">|&nbsp;&nbsp;&nbsp;&nbsp;用户中心</div>
    <div class="search_con fr">
        <form method="get" action="" target="_blank">
            <input type="text" class="input_text fl" name="q" placeholder="搜索商品">
            <input type="submit" class="input_btn fr" value="搜索">
        </form>
    </div>
</div>
<div class="main_con clearfix">
    <div class="left_menu_con clearfix">
        <h3>用户中心</h3>
        <ul>
            <li><a href="./getPersonalHtml">· 个人信息</a></li>
            <li><a href="./getOrderHtml?userId=${sessionScope.user.id}">· 全部订单</a></li>
            <li><a href="#" class="active">· 收货地址</a></li>

        </ul>
    </div>
    <!--左边目录 结束-->

    <!--右边内容 开始-->
    <div class="right_content clearfix">
        <h3 class="common_title2">
            <span>收货地址</span>
        </h3>
        <div class="site_con">
            <dl>
                <dt>默认地址：</dt>
                <dd>收货人：${curUseAddress.consignee}</dd>
                <dd>手机号：${curUseAddress.consigneePhone}</dd>
                <dd>地 &nbsp;&nbsp;址：${curUseAddress.shipAddress}</dd>
                <dd>邮编码：${curUseAddress.postCode}</dd>
                <dd style="cursor: pointer" id="address_edit"
                    onclick="xadmin.open('修改地址','./addressEditHtml?id=${curUseAddress.id}',1000,480)"><a
                        class="layui-icon layui-icon-edit"></a></dd>
            </dl>
        </div>
        <h3><a onclick="xadmin.open('添加地址','./addAddressHtml',1000,480)" style="cursor: pointer;">添加地址</a></h3>
        <hr>
        <div class="site_con">
            <dl>
                <dt>选择地址：</dt>
                <c:forEach items="${addressList}" var="address">
                    <dd>
                        <span style="padding-right: 15px">收货人：${address.consignee}</span>
                        <span style="padding-right: 15px">手机号：${address.consigneePhone}</span>
                        <span style="padding-right: 15px">地 &nbsp;&nbsp;址：${address.shipAddress}</span>
                        <span style="padding-right: 15px">邮编码：${address.postCode}</span>
                        <a style="cursor: pointer;color: green"
                           onclick="xadmin.open('修改地址','./addressEditHtml?id=${address.id}',1000,480)">修改</a>
                        <c:if test="${address.addressStatus==0}">
                            <span style="padding-right: 2px;padding-left: 2px">|</span>
                            <a style="cursor: pointer;color:green;" onclick="changeAddress(this)" data-id="${address.id}">启用</a>
                        </c:if>
                    </dd>
                </c:forEach>
            </dl>
        </div>
        <hr>
    </div>
</div>
<!--右边内容 结束-->

<!--底部 开始-->
<jsp:include page="bottom.jsp"/>
<!--底部 结束-->
<script type="text/javascript" src="./js/jquery-3.1.0.min.js"></script>
<script>
    //启用此地址
    function changeAddress(obj) {
        var id = obj.getAttribute("data-id").valueOf();
        //alert(id);
        $.ajax({
            url:"./updateAddress",
            type:"post",
            data:{id:id,addressStatus:1,userId:${sessionScope.user.id}},
            success:function (res) {
                if (res.data === "修改成功") {
                    layer.alert("修改成功", {
                            icon: 6
                        },
                        function () {
                        window.location.href="./getAddressHtml?userId=${sessionScope.user.id}";
                        });
                } else {
                    layer.msg("修改失败");
                }
            },
            error:function () {
                alert("404.html页面");
            }
        });
    }
</script>
</body>
</html>
